package com.mashibing.jvm.c3_jmm;

/**
 * 不适用
 */
public class T04_DisorderOhter {
    static int a = 0;
    static boolean flag = false;
    static class write extends Thread{
        @Override
        public void run() {
            a = 1;
            flag = true;
        }
    }

    static class reader extends Thread{
        @Override
        public void run() {
            /*if(flag){
                if(a==0) {
                    System.out.println("指令重排序了");
                }
            }*/
            if(flag){
                a=a*1;
            }
            if(a==0){
                System.out.println("ha,a==0");
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        //T04_DisorderOhter h = new T04_DisorderOhter();
        for (int i = 0; i < 10000; i++) {

            write t1 = new write();
            reader t2 = new reader();
            t1.start();t2.start();
            // t1.join();t2.join(); 不可以使用join，
            //a=0;
            //flag=false;
        }

    }
}
